/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GaoBo
 * Date: 2021-04-11
 * Time: 9:15
 */
public class TestDemo2 {

    /**
     * 1      A -> C                          1
     * 2      A -> B  A->C   B->C             3
     * 3      A->C  A->B  C->B  A->C  B->A  B->C A->C    7
     * n       2^n  -1
     * 64      2^64  -1
     * @param n 盘子的个数
     *          pos1:起始位置
     *          pos2:转换位置
     *          pos3:目的位置
     */
    public static void hanoi(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
        }else {
            hanoi(n-1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanoi(n-1,pos2,pos1,pos3);
        }
    }

    /**
     *
     * @param pos1 起始位置
     * @param pos2 目的位置
     */
    public static void move(char pos1,char pos2) {
        System.out.print(pos1 +" -> "+pos2+" ");
    }

    public static int jumpFloor(int n) {
        if(n == 1 || n == 2) {
            return n;
        }
        return jumpFloor(n-1)+jumpFloor(n-2);
    }


    public static void main(String[] args) {
        System.out.println(jumpFloor(1));//1
        System.out.println(jumpFloor(2));//2
        System.out.println(jumpFloor(3));//3
        System.out.println(jumpFloor(4));//5
        System.out.println(jumpFloor(5));//8
        /*hanoi(1,'A','B','C');
        System.out.println();
        hanoi(2,'A','B','C');
        System.out.println();
        hanoi(3,'A','B','C');
        hanoi(64,'A','B','C');*/
    }

    // func(i) =>  func(i-1)
    public static void func(int i) {
        if(i == 1) {
            return;
        }
        func(i-1);
    }

    /**
     * 阶乘的代码！
     * 递归的优点：代码量少
     * @param n
     * @return
     */
    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        return n * fac(n-1);
    }

    /**
     * %10   /10
     * @param n
     */
    public static void print(int n) {
        if(n <= 9) {
            System.out.println(n%10);
            return;
        }
        print(n/10);
        System.out.println(n%10);
    }

    public static int add(int n) {
        if(n == 1) {
            return 1;
        }
        return n+add(n-1);
    }

    //1729
    public static int add2(int n) {
        if(n > 10) {
            return add2(n/10)+n%10;
        }
        return n%10;
    }


    public static int fib(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        return fib(n-1)+fib(n-2);
    }

    public static void main5(String[] args) {
        System.out.println(fib(40));
    }


    /*public static double sum(int a,int b) {
        return a+b;
    }*/

    public static int sum(double a,int b) {
        return (int)(a+b);
    }

    // double _sum (double_,double_)
    public static double sum(double a,double b) {
        return a+b;
    }
    //int _sum(int_,int_)  方法的签名
    public static int sum(int a,int b) {
        return a+b;
    }

    public static int sum(int a,int b,int c) {
        return a+b+c;
    }
    public static int sum(int a,int b,int c,int d) {
        return a+b+c+d;
    }

    /**
     * 可变参数编程
     * @param array
     * @return
     */
    public static int sum(int... array) {
        int ret = 0;
        for (int x : array) {
            ret += x;
        }
        return ret;
    }
    //printf("%d","%f",10);
    public static void main2(String[] args) {

        int ret = sum(1,2,3,4,5,6,7,8,9,10,11,12,13);
        System.out.println(ret);

        int ret2 = sum(1,2);
        System.out.println(ret2);

        int ret3 = sum(1,2,3);
        System.out.println(ret3);

        /*int a = 10;
        int b = 20;
        System.out.println(sum(a, b));

        double c = 12.2;
        double d = 11.5;
        System.out.println(sum(c, d));*/
    }











    public static void swap(int x,int y) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    public static void main1(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前："+a+" "+b);
        swap(a,b);
        System.out.println("交换后："+a+" "+b);
    }
}
